// -----------------------------------------------------------------------
//  <copyright file="IDbContext.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2022 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2022-10-30 23:05</last-date>
// -----------------------------------------------------------------------

namespace DaprPlus.Domain.Entity;

/// <summary>
/// 定义数据上下文接口
/// </summary>
public interface IDbContext
{
    /// <summary>
    /// 获取 动态查询数据源
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    /// <returns></returns>
    IQueryable<TEntity> Query<TEntity>() where TEntity : class, IEntity;

    /// <summary>
    /// 将数据上下文转换为从库查询模式
    /// </summary>
    void ToSlave();

    /// <summary>
    /// 将数据上下文转换为主库命令模式
    /// </summary>
    void ToMaster();

    /// <summary>
    /// 提交数据上下文的所有变更
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns>操作影响的行数</returns>
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
